package org.ns.myblogs.pojo;

import java.util.HashMap;
import java.util.Map;

public class ResponseMap extends HashMap<String, Object> {
    private Map<String, Object> contentMap = null;
    public ResponseMap() {
        setState(0);
    }

    public static ResponseMap newInstance() {
        return new ResponseMap();
    }

    public ResponseMap setState(int state) {
        this.put("state", state);
        return this;
    }

    public ResponseMap putContent(String key, Object content) {
        if (contentMap == null) {
            contentMap = new HashMap<>();
            this.put("content", contentMap);
        }
        contentMap.put(key, content);
        return this;
    }

    public ResponseMap setMessage(String message) {
        this.put("message", message);
        return this;
    }

    public ResponseMap setPage(Integer pageNo, Integer pages, Integer pageSize, Long totalSize) {
        this.putContent("pageNo", pageNo);
        this.putContent("pages", pages);
        this.putContent("pageSize", pageSize);
        this.putContent("totalSize", totalSize);
        return this;
    }

    @Override
    public Object put(String key, Object value) {
        if (value == null) {
            return null;
        }
        return super.put(key, value);
    }
}
